package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Menu;
import cn.wolfcode.crm.qo.PageResult;
import cn.wolfcode.crm.qo.QueryObject;
import cn.wolfcode.crm.service.IMenuService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("menu")
public class MenuControoler {
    @Autowired
    private IMenuService menuService;

    /*写一个系统管理的静态菜单*/
    //json转换异常 可能没有提供get set方法
    @ResponseBody
    @RequestMapping("getMenusBySystem")
    public Object getMenusBySystem(){
        List<Menu> menus=menuService.queryAllMenu();


        return menus;
    }

    @RequestMapping("query")
    @ResponseBody
    public Object list(@ModelAttribute("qo") QueryObject qo) {
        //将数据转换成json格式
        PageResult result = menuService.queryForList(qo);

        return result;
    }

    @RequestMapping("getMenusNoSon")
    @ResponseBody
    public Object getMenusNoSon() {
        //将数据转换成json格式
        List<Menu> menus=menuService.getMenusNoSon();


        return menus;
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Menu entity){
        menuService.saveOrUpdate(entity);
        return new JSONResult();
    }
    @RequestMapping("getMenusByParentId")
    @ResponseBody
    public Object getMenusByParentId(Long id) {
        //将数据转换成json格式
        List<Menu>  result = menuService.getMenusByParentId(id);

        return result;
    }

    @RequestMapping("view")

    public String list1(Model model, Long id) {

        return "/menu/list";
    }

}
